﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Peak.Core;
using Peak.Resources;

namespace Peak.Web.Controllers.Models
{
  public static class UsersExtension
  {
    public static string SerializeToJson(this IList<User> users)
    {
      //"{'Lorem ipsum':'Lorem ipsum','Ipsum dolor':'Ipsum dolor','Dolor sit':'Dolor sit'}"
      string result = "{'0':'" + Labels.Unassigned + "','" + users.First(f => f.UserName.ToLower() == Thread.CurrentPrincipal.Identity.Name.ToLower()).Id + "':'" + Labels.Me + "',";
      foreach (User user in users.OrderBy(f => f.UserName))
      {
        if (user.UserName != Thread.CurrentPrincipal.Identity.Name)
          result += "'" + user.Id + "':'" + user.UserName + "',";
      }
      return result.Substring(0, result.Length - 1) + "}";
    }
  }
}
